#ifndef CONFIG_LOADER_H
#define CONFIG_LOADER_H

#include <string>
#include <fstream>
#include <unordered_map>
#include <sstream>

enum ConfigType {
    VIDEO_DEVICE,
    JPEG_QUALITY,
    PORT,
    SERVER_IP
};

using ConfigMap = std::unordered_map<ConfigType, std::string>;

class ConfigLoader {
public:
    ConfigMap GetConfig(const std::string& config_file) {
        std::unordered_map<ConfigType, std::string> config_map;
        std::ifstream infile(config_file);
        if (!infile.is_open()) {
            throw std::runtime_error("无法打开配置文件: " + config_file);
        }
        std::string line;
        while (std::getline(infile, line)) {
            std::istringstream iss(line);
            std::string key;
            std::string value;
            if (std::getline(iss, key, '=') && std::getline(iss, value)) {
                if (key == "video_source") {
                    config_map[VIDEO_DEVICE] = value;
                } else if (key == "jpeg_quality") {
                    config_map[JPEG_QUALITY] = value;
                } else if (key == "port") {
                    config_map[PORT] = value;
                } else if (key == "server_ip") {
                    config_map[SERVER_IP] = value;
                }
            }
        }
        return config_map;
    }
};
        


#endif // CONFIG_LOADER_H
